
import { _decorator, Component, Node, Vec2 } from 'cc';
import { BattleMapGrid } from './game/BattleMapGrid';
const { ccclass, property } = _decorator;



@ccclass('BaseItem2D')
export class BaseItem2D extends Component {
	static _id=0
	id=0  //有id 碰撞时好排序
	width=50
	height=50
	
	gridList:BattleMapGrid[]=[]
	

	constructor(){
		super()
		this.id=BaseItem2D._id++
	}

	resetGrid(){
		this.gridList.length=0
	}
	get pos():Vec2{
		return new Vec2(this.node.position.x,this.node.position.y)
	}
	set pos(pos:Vec2){
		this.node.setPosition(pos.x,pos.y,0)
	}
	getPos(out:Vec2){
		out.x=this.node.position.x
		out.y=this.node.position.y
	}
	setPos(x,y){
		this.node.setPosition(x,y)
	}
	get x():number{
		return this.node.position.x
	}
	get y():number{
		return this.node.position.y
	}
	set x(value:number){
		this.node.setPosition(value,this.node.position.y,0)
	}
	set y(value:number){
		this.node.setPosition(this.node.position.x,value,0)
	}
	
	separateVec=new Vec2() //碰撞之后，排开的位移
	useSperateVec(){
		// let len=this.separateVec.length()
		// if(len>10){
		// 	this.separateVec.normalize().multiplyScalar(10)
		// }
		this.setPos(this.x+this.separateVec.x,this.y+this.separateVec.y)
		this.separateVec.set(0,0)
	}
}


